1 00:00:00,230 --> 00:00:04,460 So in order to start coding my property stuff, I'm going to start out with the game manager. 2 00:00:04,460 --> 00:00:10,170 So over here in the Explorer, in server script service, there's game manager. 3 00:00:10,190 --> 00:00:15,390 Open that up and you'll notice that we're not requiring the property manager yet. 4 00:00:15,410 --> 00:00:16,820 Let's go ahead and do that. 5 00:00:16,820 --> 00:00:24,140 So I'll go to line four up here in the variable section, do a local prop MGR and now we are going to 6 00:00:24,140 --> 00:00:25,280 require it. 7 00:00:25,490 --> 00:00:30,690 Let's say game server script Service property manager. 8 00:00:30,710 --> 00:00:35,630 Now we can call things from that module script things that aren't local to the module script. 9 00:00:36,080 --> 00:00:39,860 Now let's take a look at initialize player data. 10 00:00:40,130 --> 00:00:41,590 Scroll a little bit. 11 00:00:41,600 --> 00:00:45,660 I left this line here in case you need to clear your data store. 12 00:00:45,680 --> 00:00:46,880 Just uncomment it out. 13 00:00:46,880 --> 00:00:52,400 Run the game, the data store will be cleared out, then comment it again so you don't keep clearing 14 00:00:52,400 --> 00:00:53,090 it out. 15 00:00:53,390 --> 00:00:53,660 All right. 16 00:00:53,660 --> 00:00:56,330 Here we get our data, get async. 17 00:00:56,370 --> 00:00:58,880 The call might be unsuccessful. 18 00:00:58,880 --> 00:01:00,330 If it is kick the player. 19 00:01:00,330 --> 00:01:07,680 We couldn't reach the data store, but it could be successful and we either have data or not have data. 20 00:01:07,710 --> 00:01:10,530 If they're brand new, they don't have any data. 21 00:01:10,560 --> 00:01:15,510 I just start us out with 10,000 points because we want to buy a house In your game. 22 00:01:15,510 --> 00:01:17,070 You might want to make it zero. 23 00:01:17,100 --> 00:01:18,960 Make them work for the points. 24 00:01:18,960 --> 00:01:24,960 But if they do have data they played before, we're going to put it on their leaderboard. 25 00:01:25,170 --> 00:01:32,150 We also have to do property stuff, so let's check to see if they have any property stuff. 26 00:01:32,160 --> 00:01:34,860 We're going to do this data.property. 27 00:01:34,860 --> 00:01:38,100 We're going to store our property stuff in property. 28 00:01:38,100 --> 00:01:45,660 So if they have property, then let's take a look at our property manager and we have something like 29 00:01:45,690 --> 00:01:48,150 update player with DB info. 30 00:01:48,180 --> 00:01:51,660 We still have to fill that out in the property manager. 31 00:01:51,660 --> 00:01:57,630 We're going to pass a player and we're going to pass the data.property, right? 32 00:01:57,630 --> 00:02:00,720 So here they got property stuff down here. 33 00:02:00,720 --> 00:02:01,470 They're brand new. 34 00:02:01,500 --> 00:02:06,660 You can put a little note if you want, maybe a print out, print new player. 35 00:02:08,760 --> 00:02:12,060 Let's go to save player data right here. 36 00:02:12,570 --> 00:02:15,980 And I left a note save player property stuff. 37 00:02:15,990 --> 00:02:17,070 Let's do that. 38 00:02:18,060 --> 00:02:24,390 I'm going to do data.property equals. 39 00:02:24,540 --> 00:02:26,310 We'll get our prop manager. 40 00:02:26,430 --> 00:02:32,470 Get player items to save and we're going to need the player to get those items. 41 00:02:32,490 --> 00:02:33,520 Nice. 42 00:02:33,540 --> 00:02:34,390 Now go down. 43 00:02:34,440 --> 00:02:36,030 Save loop is going to be identical. 44 00:02:36,030 --> 00:02:37,680 We're not going to change anything. 45 00:02:37,680 --> 00:02:44,550 But down here in our player added, we are going to give the player the property. 46 00:02:44,550 --> 00:02:46,620 So they just got added to the game. 47 00:02:46,620 --> 00:02:48,300 Let's give them some property. 48 00:02:48,300 --> 00:02:50,760 If they have it, they may not have bought any. 49 00:02:51,690 --> 00:02:57,330 Let's do a property manager, colon equip player. 50 00:02:58,530 --> 00:02:59,400 There we go. 51 00:02:59,400 --> 00:03:03,390 So I even kept that the same as in the equipment manager equip player. 52 00:03:03,420 --> 00:03:06,350 You equip them with property or you equip them with weapons. 53 00:03:06,360 --> 00:03:08,980 I thought it would be fine to leave it the same. 54 00:03:08,980 --> 00:03:11,350 It's easier to figure out what's going on. 55 00:03:12,070 --> 00:03:15,370 Now let's take a look at our property manager script. 56 00:03:15,400 --> 00:03:20,170 This is a module script, so I'm in server script service over here in the Explorer. 57 00:03:20,170 --> 00:03:26,890 I'm going to double click on property Manager and this is what we're requiring from the other script. 58 00:03:26,890 --> 00:03:29,680 That's the table that holds the functions that we're going to use. 59 00:03:29,710 --> 00:03:32,080 This is going to hold our data. 60 00:03:32,800 --> 00:03:37,720 I want to define another variable for the collection of lots. 61 00:03:37,720 --> 00:03:41,930 So we could have, let's say if there's six people on our server, we're going to need at least six 62 00:03:41,930 --> 00:03:45,550 slots and if there's 20 people, we're going to need like 20 lots. 63 00:03:45,550 --> 00:03:49,840 So I want to get a variable holding all of those lots. 64 00:03:49,840 --> 00:03:53,320 So I'm going to say lot collection. 65 00:03:53,320 --> 00:03:58,660 And if you'll notice here, we only have a single lot. 66 00:03:58,930 --> 00:04:07,510 I think I'm going to click on Player lot over here in the Explorer right click group as model and this 67 00:04:07,510 --> 00:04:09,430 is going to be my lot collection. 68 00:04:09,430 --> 00:04:11,950 I'm just going to call it lots. 69 00:04:11,980 --> 00:04:17,380 It's the collection of lots, so we'll have several player lots under the lots. 70 00:04:17,770 --> 00:04:28,690 And then I'm going to do a workspace dot lots colon, get children and that way I'm going to have a 71 00:04:28,690 --> 00:04:33,400 table for every single lot in my in my world, in my scene. 72 00:04:34,970 --> 00:04:41,750 Add item to player's inventory is going to be called when we buy the lot or if we buy the house or we 73 00:04:41,750 --> 00:04:42,800 make an upgrade. 74 00:04:42,800 --> 00:04:43,130 Right. 75 00:04:43,130 --> 00:04:44,680 We're going to get back to that. 76 00:04:44,690 --> 00:04:47,090 Let's go down to equip player. 77 00:04:47,090 --> 00:04:51,710 We're calling that in the game manager when we're equipping our player when he's entering the game, 78 00:04:51,920 --> 00:04:53,750 let's get rid of the print statement. 79 00:04:53,780 --> 00:04:55,670 We can populate this out now. 80 00:04:55,670 --> 00:05:03,470 So first thing I'm going to do is check to see in our property table if the property table has a slot 81 00:05:03,470 --> 00:05:11,210 for the player and if the property table slot for that player has a value. 82 00:05:11,210 --> 00:05:15,650 That's true for has a lot, right? 83 00:05:15,650 --> 00:05:22,340 If that is true, then we need to look in these slots, find an empty one and give it to the player. 84 00:05:22,340 --> 00:05:23,540 He bought a lot. 85 00:05:23,570 --> 00:05:25,190 Now he's entering the game again. 86 00:05:25,190 --> 00:05:26,470 We got to give him a lot. 87 00:05:26,480 --> 00:05:35,360 So I'm going to say for I and V in pairs, we're going to look through the lot collection. 88 00:05:35,360 --> 00:05:43,040 Do if a lot is not owned by anybody, we're going to give it to the player entering the game. 89 00:05:43,040 --> 00:05:56,000 So I'll say if not V that's the lot owner dot value than so owner value is a string value of the player's 90 00:05:56,030 --> 00:05:56,570 name. 91 00:05:56,570 --> 00:05:58,430 But I am going to change that. 92 00:05:58,430 --> 00:06:03,890 I think I want to put the entire player in this owner tag right here. 93 00:06:03,890 --> 00:06:07,370 So I'm going to right click on this owner tag and delete it. 94 00:06:08,150 --> 00:06:09,620 And I'm going to put. 95 00:06:10,310 --> 00:06:14,990 Another tag for object value. 96 00:06:15,020 --> 00:06:18,710 I'm going to name it the exact same thing, so I'm going to name that owner. 97 00:06:18,710 --> 00:06:23,990 And now I'm going to put the whole player in there, not just the name, in case I want stuff from the 98 00:06:23,990 --> 00:06:24,410 player. 99 00:06:24,410 --> 00:06:26,570 I can get it right from that owner tag. 100 00:06:26,870 --> 00:06:27,770 Let's see. 101 00:06:27,770 --> 00:06:32,580 So we'll have V that's the owner owner value. 102 00:06:32,600 --> 00:06:40,670 Now nobody owns this lot, so we can put the player in that value and we're going to get the name of 103 00:06:40,670 --> 00:06:42,710 the player and put it on the sign. 104 00:06:42,710 --> 00:06:43,030 Right? 105 00:06:43,100 --> 00:06:51,530 It said for sale, for sale sign and it was of type sign. 106 00:06:51,530 --> 00:06:53,630 Let's take a look for sale sign. 107 00:06:54,470 --> 00:06:56,090 There's our sign. 108 00:06:56,090 --> 00:07:02,480 We have a surface guy we want that text label probably should have made those shorter names. 109 00:07:02,480 --> 00:07:15,120 So we'll say surface guy text, label, text and let's put their name in there like player.name. 110 00:07:15,120 --> 00:07:18,090 And you could say like player names, house or whatever you want. 111 00:07:18,120 --> 00:07:20,670 This is just a string that goes right here. 112 00:07:21,960 --> 00:07:25,080 Now, once we've done that, players got a lot. 113 00:07:25,110 --> 00:07:26,760 We don't have to keep going through lots. 114 00:07:26,760 --> 00:07:28,500 We could break out of this. 115 00:07:29,500 --> 00:07:29,770 All right. 116 00:07:29,770 --> 00:07:32,110 We have a few more small things in here. 117 00:07:32,140 --> 00:07:39,160 This update player with DB info when the game manager reads the data for a player entering the game. 118 00:07:39,160 --> 00:07:43,450 We're going to send that data here so we could use it in our module script. 119 00:07:43,480 --> 00:07:46,740 Let's get our property for that player. 120 00:07:46,780 --> 00:07:51,460 A property table for that player and set the data that was found in the data store. 121 00:07:52,070 --> 00:07:57,560 Then while we're going to save data off either in the save loop or when they're leaving, we're going 122 00:07:57,560 --> 00:08:02,930 to return the property player data. 123 00:08:03,560 --> 00:08:10,130 And then down here, I have this to check to see if a player is trying to buy another lot and they already 124 00:08:10,130 --> 00:08:10,970 own a lot. 125 00:08:11,000 --> 00:08:18,080 So it's just a utility function, let's say if property for the player exists. 126 00:08:18,470 --> 00:08:28,340 If that entry does exist, then let's check to see if the property player has a lot. 127 00:08:30,040 --> 00:08:30,820 I got that right. 128 00:08:30,850 --> 00:08:31,750 Has a lot. 129 00:08:32,950 --> 00:08:33,460 Yeah. 130 00:08:33,880 --> 00:08:34,600 There we go. 131 00:08:34,600 --> 00:08:36,910 All right, So if we have the lot, then we're going to return. 132 00:08:36,910 --> 00:08:37,600 True. 133 00:08:38,350 --> 00:08:45,970 And else there's either no data in here for the player or we don't have the lot. 134 00:08:46,000 --> 00:08:48,640 Flags switch to true. 135 00:08:48,670 --> 00:08:51,760 Then we'll return a false a little bit redundant here. 136 00:08:51,760 --> 00:08:51,900 Right? 137 00:08:51,910 --> 00:08:55,570 Because if we have if we have property data, it's because we have a lot. 138 00:08:55,600 --> 00:08:56,950 But we may want to change that. 139 00:08:56,950 --> 00:08:59,530 We may want to have different types of property without a lot. 140 00:09:00,100 --> 00:09:00,310 All right. 141 00:09:00,310 --> 00:09:03,910 Let's go ahead and play our game, see if we have any errors in the output window. 142 00:09:03,910 --> 00:09:05,080 Hit play. 143 00:09:06,210 --> 00:09:08,240 And I have my view tab selected already. 144 00:09:08,250 --> 00:09:09,000 Go ahead and select it. 145 00:09:09,000 --> 00:09:13,290 If you don't open up the output window, check for errors. 146 00:09:13,290 --> 00:09:15,150 You may have something that says like new player. 147 00:09:15,150 --> 00:09:17,700 Remember we put that printout down there for new players. 148 00:09:17,700 --> 00:09:22,530 I played my game since I created the data store, so I am not a new player. 149 00:09:22,620 --> 00:09:23,220 All right. 150 00:09:23,220 --> 00:09:27,360 I will see you in the next video and we're going to get that buying stuff going.